<template>
  <div class="dialog mask" v-show="open">
    <div class="popup-wrapper">
      <i class="popup-close" @click.stop="onClose"></i>
      <h5 class="popup-title">{{ title }}</h5>
      <div class="popup-content">
        <NewDraw v-if="openNewDraw" :onClose="onClose" />
        <CodeShow v-if="openCodeShow" :options="options" :onClose="onClose" />
        <About v-if="openAbout" :onClose="onClose" />
      </div>
    </div>
  </div>
</template>

<script>
import NewDraw from "./NewDraw.vue";
import CodeShow from "./CodeShow.vue";
import About from "./About.vue";
export default {
  components: {
    NewDraw,
    CodeShow,
    About
  },
  data() {
    return {
      open: false,
      openNewDraw: false,
      openCodeShow:false,
      openAbout:false,
      options:null,
      title: "NULL",
    };
  },
  created() {
    this.$bus.$on("openNewDraw", () => {
      this.open = true;
      this.openNewDraw = true;
      this.title = NewDraw.name;
    });

    this.$bus.$on("openCodeShow", ({type,code}) => {
      this.open = true;
      this.openCodeShow = true;
      this.options = {type,code};
      this.title = `${type.toUpperCase() || "NULL"}`;
    });

    this.$bus.$on("openAbout", () => {
      this.open = true;
      this.openAbout = true;
      this.title = About.name;
    });
  },
  watch:{
      open(v){
        if(!v) {
              this.openNewDraw = v;
              this.openCodeShow = v;
              this.openAbout = v;
              this.options = null;
        }
      }
  },
  mounted() {},
  methods: {
    onClose() {
      this.open = false;
    },
  },
};
</script>

<style scoped lang="scss">
.popup-wrapper {
  display: block;
  width: 50%;
  background-color: #222;
  min-width: 360px;
  max-width: 1200px;
  position: absolute;
  left: 50%;
  top:50%;
  transform: translate(-50%,-50%);
  z-index: 9;
  border-radius: 5px;
  overflow: hidden;
  margin: 0 auto 40px;

  .popup-close {
    display: block;
    position: absolute;
    top: 12px;
    right: 8px;
    background: url("../assets/icon/close.png") no-repeat;
    background-size: 100% auto;
    width: 32px;
    height: 32px;
    cursor: pointer;
  }
  .popup-content {
    box-sizing: border-box;
    height: auto;
    width: 100%;
    background-color: #222;
    box-shadow: 1px 0px 5px #0b0b0b inset;
    padding: 20px;
    overflow-x: hidden;
  }
  .popup-title {
    text-align: left;
    padding: 20px;
    color: #fff;
    font-size: 16px;
    line-height: 14px;
     box-shadow: 1px 0px 5px #0b0b0b inset;
    font-family: "Oswald";
    background-color: #1f1f1f;
  }
}
.mask {
  display: block;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 999;
  background-color: rgba(0, 0, 0, 0.5);
  padding: 0% 0;
  overflow: auto;
}
</style>
